<script>
  
var SmallestInfiniteSet = function() {
    this.num = 1;
    this.set = new Set();
};

/**
 * @return {number}
 */
SmallestInfiniteSet.prototype.popSmallest = function() {
    const arr = [...this.set].sort((a,b)=>a-b);
    let ans;
    if(arr[0]<this.num){
        ans = arr[0];
        this.set.delete(ans);
    }else{
        ans = this.num;
        this.num++;
    }
    return ans;
};

/** 
 * @param {number} num
 * @return {void}
 */
SmallestInfiniteSet.prototype.addBack = function(num) {
    if(num<this.num){
        this.set.add(num);
    }
};

/**
 * Your SmallestInfiniteSet object will be instantiated and called as such:
 * var obj = new SmallestInfiniteSet()
 * var param_1 = obj.popSmallest()
 * obj.addBack(num)
 */
</script>